require('../css/course.css');
//导入axios
const axios = require('../utils/http.js');

window.onload=function(){

    const BASE_URL = 'http://47.96.154.185:3701';
    let img = document.querySelector('.video img');
    let tit1 = document.querySelector('.tit1');
    let illustrate = document.querySelector('.illustrate');
    let timeDom = document.querySelector('.span1');
    let avatarImg = document.querySelector('.user_name img');
    let btn =document.querySelector('.btn');

    let upper = document.querySelector('#upper');
    let play = document.querySelector('#play');
    let userName = document.querySelector('.userName');
    
    
    //存视频数组全局
    let videoList = [];

    //拿到上个页面的a标签传的值
    let urlData = location.search;
    console.log(urlData);
    
    //页面传值渲染
    axios.get('/api/train/courseDetail'+urlData).then(res=>{
        console.log(res);
        let data = res.data.data;
        img.src = BASE_URL+data.imgurl;
        tit1.innerText = data.name;
        illustrate.innerText = data.desc;
        timeDom.innerText = data.calorie;
        videoList = data.fragments;
        
    })

    //点击训练按钮跳转
    btn.addEventListener('click',function(){
        sessionStorage.setItem('videoList',JSON.stringify(videoList));
        location.href = './play.html';
    })
    //点击回到上一层
    upper.addEventListener('click',function(){
        location.href='./sport.html';
    })
    //点击播放按钮
    play.addEventListener('click',function(){
        btn.click();
    })

    //头像刷新
    axios.get('/api/user/info').then(function(res){
        console.log(res);
        let data = res.data.data;
        avatarImg.src = BASE_URL+data.imgUrl;
        userName.textContent = data.nickName;
    })
}
